Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate function call json schemas for openai #1156

Merged
merged 9 commits into from
Feb 12, 2025

Conversation

wendytang
Copy link
Collaborator

@wendytang wendytang commented Feb 8, 2025

Users reporting openai incompatibility with certain extensions.

Fixes #933, related to #945

Extensions are not providing valid json schemas for openai function tool calling. Adds a function to validate the schema and add missing json schema fields

    "function": {
        "name": "get_weather",
        "description": "Get current temperature for a given location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and country e.g. Bogotá, Colombia"
                }
            },
            "required": [
                "location"
            ],
            "additionalProperties": False
        },
        "strict": True
    }

Databricks likely handled the missing fields on their end.

Tests:

  • jetbrains tool call successful with openai, gpt4o, o1, o3-mini
  • jetbrains tool call successful with databricks, goose

@wendytang wendytang marked this pull request as ready for review February 8, 2025 01:08
@wendytang wendytang changed the title fix: validate tool schemas for openai post request fix: validate function call schemas for openai post Feb 8, 2025
@wendytang wendytang changed the title fix: validate function call schemas for openai post fix: validate function call schemas Feb 8, 2025
@wendytang wendytang changed the title fix: validate function call schemas fix: validate function call schemas for openai Feb 8, 2025
@wendytang wendytang requested a review from Kvadratni February 8, 2025 01:12
@angiejones
Copy link
Collaborator

bless you 🙌🏾

@wendytang wendytang changed the title fix: validate function call schemas for openai fix: validate function call json schemas for openai Feb 10, 2025
Copy link

github-actions bot commented Feb 10, 2025

PR Preview Action v1.6.0

🚀 View preview at
https://block.github.io/goose/pr-preview/pr-1156/

Built to branch gh-pages at 2025-02-12 07:20 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

if prop.is_object()
&& (prop.get("type").and_then(|t| t.as_str()) == Some("object"))
{
ensure_valid_json_schema(prop);
Copy link
Collaborator Author

@wendytang wendytang Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could put a recursive counter here, but I don't think extensions are going to have massively nested json schemas

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I would hope they wouldn't!

if let Some(properties_obj) = properties.as_object_mut() {
for (_key, prop) in properties_obj.iter_mut() {
if prop.is_object()
&& (prop.get("type").and_then(|t| t.as_str()) == Some("object"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to set default to true like line 277?

crates/goose/src/providers/formats/openai.rs Outdated Show resolved Hide resolved
@wendytang wendytang closed this Feb 11, 2025
@wendytang wendytang reopened this Feb 11, 2025
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh very nice!

I wonder if we need similar thing for gemini too!

@wendytang wendytang merged commit 80b694d into main Feb 12, 2025
6 of 7 checks passed
@wendytang wendytang deleted the wtang/debug_payload branch February 12, 2025 07:20
laanak08 pushed a commit that referenced this pull request Feb 13, 2025
Co-authored-by: angiejones <jones.angie@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jetbrains extension fails with gpt-4o
6 participants